#!/bin/bash
function Usage() {
    echo "Usage : $0"

}

if [[ $# -ge 1 ]];then
    Usage
    exit 1
fi

Nowtime=`date +"%Y-%m-%d %H:%M:%S"`
UserCnt=`wc -l /etc/passwd | cut -d " " -f 1`
users=`last | awk -v cnt=0 '{if(substr($2,1,3) == "pts") print $1;}' | sort | uniq -c | sort -nr | awk '{if(NR <= 3) {print $2}}'`
flag=0
CurrUser=""

for user in ${users}; do
    if [[ ${flag} -gt 0 ]];then
        CurrUser=${CurrUser},
    fi
    CurrUser=${CurrUser}${user}
    flag+=1;
done

sudoers=`cat /etc/group | grep sudo | cut -d ":" -f 4`

doWhat=`w -h | awk -v n=0 '{ if(n > 0) {printf(",")}; printf("%s_%s_%s_%s", $1, $3, $2, $8); n++} END {printf("\n")}'`

echo "${Nowtime} $CurrUser ${sudoers} ${doWhat}"
